<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            height: 100px;
            margin: 200px auto;
        }

        .box input {
            width: 100px;
            height: 20px;
            border: 1px solid blueviolet;
            outline: none;
        }

        .box .btn {
            display: inline-block;
            height: 23px;
            width: 20px;
            background-color: blueviolet;
        }

        .message {
            display: inline-block;
            padding-left: 14px;
            background-color: #ccc;
            background: url('images/mess.png') no-repeat left center;
            color: #ccc;
            background-position: 0 0;
        }

        .error {
            background: url('images/wrong.png') no-repeat left center;
            color: red;
        }

        .pass {
            background: url('images/right.png') no-repeat left center;
            color: green;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="password" name="" id="">
        <!-- <div class="btn"></div> -->
        <p class="message">请输入6-16位密码</p>
    </div>
    <script>
        var input = document.querySelector('input');
        // var btn = document.querySelector('.btn');
        var ico = document.querySelector('span');
        var p = document.querySelector('p');

        input.onblur = function () {
            if (input.value.length < 6 || input.value.length > 16) {
                // console.log(input.value);
                console.log('no!');
                p.className = 'message error';
                p.innerHTML = '您输入的字数不对，请输入6-16个字符';
            }
            else {
                p.className = 'message pass';
                p.innerHTML = '通过！';
            }
        }
    </script>

</body>

</html>